<?
  include "common/db_conn.php";

  header("Cache-Control:no-cache");
  header("Pragma:no-cache");
  
  session_start();

  $sm_idx = $_SESSION["sm_idx"];
    
  //echo("SESSION sm_idx[$sm_idx]<br>");
  
  $code = $_GET["code"];
  
  $query_m = "select sm_idx, sm_code, sm_start, sm_state from sv_member where sm_code = '$code' limit 1";
  $result_m = mysql_query($query_m);
  $rows_m = mysql_fetch_array($result_m);
  
  //echo("query_m[$query_m]<br>");
  
  $sm_idx = $rows_m["sm_idx"];
  $sm_code = $rows_m["sm_code"];
  $sm_start = $rows_m["sm_start"]; 
  $sm_state = $rows_m["sm_state"];
  
  if ($sm_idx == "") {
    echo("ILLEGAL ACCESS");
    exit(0);
  }
  
  
  $query_m = "select sm_state from sv_member where sm_idx = $sm_idx";
  $result_m = mysql_query($query_m);
  $rows_m = mysql_fetch_array($result_m);
  $sm_state = $rows_m["sm_state"];
  
  //echo("sm_state[$sm_state]<br>");
  if ($sm_state == 1) {
?> 
<script>
  location.href = "close.html";
</script>
<?  
    exit(0);
  }
  
  
  if ($sm_start != "") {  // 이미 동의함
    $checked = " checked disabled"; 
    $agree_desc = substr($sm_start, 0, 10)."에 이미 동의하셨습니다.";
  } else {
    $checked = "";    
    $agree_desc = "";
  }
  
  //echo("code[$code] sm_idx[$sm_idx] sm_code[$sm_code] sm_start[$sm_start] sm_state[$sm_state]<br>");
  
  
  $query_b = "select sb_text from sv_base where sb_idx = 1 limit 1";
  $result_b = mysql_query($query_b);
  $rows_b = mysql_fetch_array($result_b);
  $notice = nl2br(stripslashes($rows_b["sb_text"]));
?>
<!DOCTYPE html>
<html>
<head>
<link href="common/style.css" rel="stylesheet" type="text/css" media="all" />
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width, height=device-height" />
<script>
  function goNext()
  {
    if  (document.frm.agree.checked == true) {
      return true;
    } else {
      alert("연구에 참여하고 협조할 것에 동의하셔야 합니다.");
      return false;
    }
  }
</script>
</head>
<body>
<!--
<img align="center" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSnPNnQ68sPPi3YzwmfaRv5Nd4D4DFmoxKdsv71ZzCB9ehawWQC">
-->
<form name="frm" method="post" target="ifr" action="s_proc.php" onSubmit="return goNext()">
  <input type="hidden" name="ptype" value="1">
  <input type="hidden" name="code" value="<?=$sm_code?>">
  <div>
    <?=$notice?><input type="checkbox" name="agree"<?=$checked?>><?=$agree_desc?>
  </div>
  <div>
  <? if ($sm_start != "") { ?>
    <input type="submit" value="설문으로 가기">
  <? } else { ?>
    <input type="submit" value="동의합니다">
  <? } ?>
  </div>
</form>

<iframe src="about:blank" name="ifr" width="0" height="0" style="display:none;"></iframe>
</body>
</html>
<?
  include "common/db_close.php";
?>
